package softtest4;

import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class Bill1 {
  public   long calculateTimeSpan(String startTime, String endTime){
    ZonedDateTime time1 = ZonedDateTime.parse(startTime);
    ZonedDateTime time2 = ZonedDateTime.parse(endTime);

    Duration duration = Duration.between(time1, time2);

    long minutes = duration.getSeconds() / 60;
    if (duration.getSeconds() % 60 > 0) {
      minutes++;
    }

    // 判断是否需要调整时间以处理夏令时和冬令时的情况
    if (!isDaylightTime(time1, time1.getZone()) && isDaylightTime(time2, time2.getZone())) {
      minutes=minutes-60; // 如果开始时间不在夏令时，结束时间在夏令时，减去60分钟
    }

    return minutes;
  }

  // 判断是否是夏令时
  public static boolean isDaylightTime(ZonedDateTime dateTime, ZoneId zoneId) {
    return zoneId.getRules().isDaylightSavings(dateTime.toInstant());
  }
  //计算价格
  public double countMoney(long time){
    double money = 0;
    if(time <= 0|| time >1800){
      money = -1.0;
    }
    else if(time > 0 && time <=20){
      money = time*0.05;
    }

    else
      money = 1+(time - 20)*0.1;

    return money;
  }




}
